'Disable close button in Userform
'Creat Userform add two buttons in it.
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

Private Const SC_CLOSE As Long = &HF060
Private Const SW_SHOW As Long = 5

Private hwnd, hMenu, lStyle As Long
Sub DisableClose()
hwnd = FindWindow("ThunderDFrame", Me.Caption)
hMenu = GetSystemMenu(hwnd, 0)
DeleteMenu hMenu, SC_CLOSE, 0&
ShowWindow hwnd, SW_SHOW
DrawMenuBar hwnd
End Sub
Sub EnableClose()
hwnd = FindWindow("ThunderDFrame", Me.Caption)
hMenu = GetSystemMenu(hwnd, 1)
ShowWindow hwnd, SW_SHOW
DrawMenuBar hwnd
End Sub

Private Sub CommandButton2_Click()
Call EnableClose
End Sub
Private Sub CommandButton1_Click()
Call DisableClose
End Sub

